﻿// LessonTable.cpp : 实现文件
//

#include "stdafx.h"
#include "学生管理系统MFC.h"
#include "LessonTable.h"
#include "afxdialogex.h"


// CLessonTable 对话框

IMPLEMENT_DYNAMIC(CLessonTable, CDialog)

CLessonTable::CLessonTable(CWnd* pParent /*=NULL*/)
	: CDialog(IDD_LESSONTABLE, pParent)
{

}

CLessonTable::~CLessonTable()
{
}

void CLessonTable::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_list);
}


BEGIN_MESSAGE_MAP(CLessonTable, CDialog)
	ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()


// CLessonTable 消息处理程序


BOOL CLessonTable::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化
	// TODO: Add extra initialization here   
	CRect rect;
	// 获取编程语言列表视图控件的位置和大小   
	m_list.GetClientRect(&rect);
	// 为列表视图控件添加全行选中和栅格风格   
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	m_list.InsertColumn(0, _T("课头号"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(1, _T("课程名"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(2, _T("课程类型"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(3, _T("学习类型"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(4, _T("授课学院"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(5, _T("教师"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(6, _T("专业"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(7, _T("学分"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(8, _T("学时"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(9, _T("上课时间"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(10, _T("备注"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(11, _T("状态"), LVCFMT_CENTER, rect.Width() / 3, 0);
	
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

void CLessonTable::Query()
{
	CString sql;
	//m_username = _T("2014301500095");
	sql = _T("SELECT DISTINCT dbo.[课程].[课头号],dbo.[课程].[课程名],dbo.[课程].[课程类型],dbo.[课程].[学习类型],dbo.[课程].[授课学院],dbo.[教师].[姓名],dbo.[课程].[专业],dbo.[课程].[学分],dbo.[课程].[学时],dbo.[课程].[上课时间],dbo.[课程].[上课校区],dbo.[课程].[上课地点],dbo.[课程].[备注] FROM dbo.[成绩], dbo.[学生], dbo.[课程],教师 WHERE 教师.工号=课程.教师 AND dbo.[学生].[学号] = ") + m_username + _T(" AND dbo.[学生].[学号] = dbo.[成绩].[学号] AND dbo.[课程].[课头号] = dbo.[成绩].[课头号] AND dbo.[成绩].[学年] = ") + m_year + _T(" AND dbo.[成绩].[学期] = '") + m_term + _T("'");
	::CoInitialize(NULL);
	g_pDB->Initialize(ConnectionAddress, ConnectionDB, ConnectionUser, ConnectionPassword);
	CSqlStatement *stmt = g_pDB->ExecuteSQL(sql);
	while (stmt != NULL)
	{
		if (stmt->NextRow() == NULL)
		{
			break;
		}
		int nRow = m_list.InsertItem(0, stmt->ValueString(_T("课头号")));//插入行
		m_list.SetItemText(nRow, 1, stmt->ValueString(_T("课程名")));//设置数据
		m_list.SetItemText(nRow, 2, stmt->ValueString(_T("课程类型")));//设置数据
		m_list.SetItemText(nRow, 3, stmt->ValueString(_T("学习类型")));//设置数据
		m_list.SetItemText(nRow, 4, stmt->ValueString(_T("授课学院")));//设置数据
		m_list.SetItemText(nRow, 5, stmt->ValueString(_T("姓名")));//设置数据
		m_list.SetItemText(nRow, 6, stmt->ValueString(_T("专业")));//设置数据
		m_list.SetItemText(nRow, 7, stmt->ValueString(_T("学分")));//设置数据
		m_list.SetItemText(nRow, 8, stmt->ValueString(_T("学时")));//设置数据
		CString 上课时间地点 = stmt->ValueString(_T("上课时间")) + _T(",") + stmt->ValueString(_T("上课校区")) + _T(",") + stmt->ValueString(_T("上课地点"));
		m_list.SetItemText(nRow, 9, 上课时间地点);//设置数据
		m_list.SetItemText(nRow, 10, stmt->ValueString(_T("备注")));//设置数据
																  //m_list.SetItemText(nRow, 11, stmt->ValueString(_T("状态")));//设置数据
	}
	delete stmt;
	::CoUninitialize();
}
void CLessonTable::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);
	if (bShow == true)
	{
		m_list.DeleteAllItems();
		Query();
	}
	// TODO: 在此处添加消息处理程序代码
}
void CLessonTable::OnOK()
{

}